package com.tianqu.tms.www.check.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAjaxAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.core.util.StringUtil;
import com.tianqu.tms.entity.Codes;
import com.tianqu.tms.entity.TransferAcceptedInfo;
import com.tianqu.tms.www.check.controller.CheckCarPrintCheckAjaxController;

/**
 * @author zhangxueliang 打印查验表
 */
public class CheckCarPrintCheckAjaxAction extends TmsAjaxAction {
	private Logger logger = Logger
			.getLogger(CheckCarPrintCheckAjaxAction.class);
	public static final String SERIAL = "serial";

	@Override
	public void process(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws TmsException {
		logger.debug(this.getClass().getName() + "#execute was called.");
		String serial = request.getParameter("serial");
		uc.setAttribute(SERIAL, serial);
		CheckCarPrintCheckAjaxController controller = new CheckCarPrintCheckAjaxController();
		try {
			controller.execute(uc);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		TransferAcceptedInfo transferAcceptedInfo = TransferAcceptedInfo.getInstance();
		Codes code = Codes.getInstance();
		transferAcceptedInfo = (TransferAcceptedInfo) uc.getAttribute(CheckCarPrintCheckAjaxController.TRANSFERACCEPTEDINFO);
		String lvin = "";
		String registration = "";
		String transferRegister = "";
		String changesVacate = "";
		String vinNum = "√";
		String engineNum = "——";
		String brandModel = "——";
		String drivingRecord = "——";
		String plateOrTireExterior = "——";
		String tireIntact = "——";
		String seatBelt = "——";
		String numberAxes = "——";
		String tireSize = "——";
		String lateralPortionOf = "——";
		String reflectiveMark = "——";
		String fireExtinguisher = "——";
		String security = "——";
		String externalMarking = "——";
		String siren = "——";
		String securityTechnology = "——";

		if (transferAcceptedInfo.getRegistration() == 1) {// 注册登记
			registration = "√";
		}
		if (transferAcceptedInfo.getTransferRegister() == 1) {// 转移登记
			transferRegister = "√";
		}
		if (transferAcceptedInfo.getChangesVacate() == 1) {// 变更迁出
			changesVacate = "√";
		}
		if ("1".equals(transferAcceptedInfo.getVinNum())) {// 车辆识别代号-----------------------------
			vinNum = "√";
		}
		if (transferAcceptedInfo.getVinNum() == null|| "".equals(transferAcceptedInfo.getVinNum())) {
			vinNum = "";
		}
		if ("1".equals(transferAcceptedInfo.getEngineNum())) {// 发动机型号/代码
			engineNum = "√";
		}
		if (transferAcceptedInfo.getEngineNum() == null|| "".equals(transferAcceptedInfo.getEngineNum())) {
			engineNum = "";
		}
		if ("1".equals(transferAcceptedInfo.getBrandModel())) {// 车辆品牌/型号
			brandModel = "√";
		}
		if (transferAcceptedInfo.getBrandModel() == null|| "".equals(transferAcceptedInfo.getBrandModel())) {
			brandModel = "";
		}
		if ("1".equals(transferAcceptedInfo.getPlateOrTireExterior())) {// 号牌/车辆外观形状
			plateOrTireExterior = "√";
		}
		if (transferAcceptedInfo.getPlateOrTireExterior() == null|| "".equals(transferAcceptedInfo.getPlateOrTireExterior())) {
			plateOrTireExterior = "";
		}
		if ("1".equals(transferAcceptedInfo.getTireIntact())) {// 轮胎完好情况
			tireIntact = "√";
		}
		if (transferAcceptedInfo.getTireIntact() == null|| "".equals(transferAcceptedInfo.getTireIntact())) {
			tireIntact = "";
		}
		if ("1".equals(transferAcceptedInfo.getSeatBelt())) {// 安全带、三角警告牌
			seatBelt = "√";
		}
		if (transferAcceptedInfo.getSeatBelt() == null|| "".equals(transferAcceptedInfo.getSeatBelt())) {
			seatBelt = "";
		}
		if ("1".equals(transferAcceptedInfo.getNumberAxes())) {// 外廓尺寸、轴数
			numberAxes = "√";
		}
		if (transferAcceptedInfo.getNumberAxes() == null
				|| "".equals(transferAcceptedInfo.getNumberAxes())) {
			numberAxes = "";
		}
		if ("1".equals(transferAcceptedInfo.getTireSize())) {// 轮胎规格
			tireSize = "√";
		}
		if (transferAcceptedInfo.getTireSize() == null
				|| "".equals(transferAcceptedInfo.getTireSize())) {
			tireSize = "";
		}
		if ("1".equals(transferAcceptedInfo.getLateralPortionOf())) {// 侧后部防护装置
			lateralPortionOf = "√";
		}
		if (transferAcceptedInfo.getLateralPortionOf() == null
				|| "".equals(transferAcceptedInfo.getLateralPortionOf())) {
			lateralPortionOf = "";
		}
		if ("1".equals(transferAcceptedInfo.getReflectiveMark())) {// 车身反光标示
			reflectiveMark = "√";
		}
		if (transferAcceptedInfo.getReflectiveMark() == null
				|| "".equals(transferAcceptedInfo.getReflectiveMark())) {
			reflectiveMark = "";
		}
		if ("1".equals(transferAcceptedInfo.getFireExtinguisher())) {// 灭火器
			fireExtinguisher = "√";
		}
		if (transferAcceptedInfo.getFireExtinguisher() == null
				|| "".equals(transferAcceptedInfo.getFireExtinguisher())) {
			fireExtinguisher = "";
		}
		if ("1".equals(transferAcceptedInfo.getDrivingRecord())) {// 行驶记录装置
			drivingRecord = "√";
		}
		if (transferAcceptedInfo.getDrivingRecord() == null
				|| "".equals(transferAcceptedInfo.getDrivingRecord())) {
			drivingRecord = "";
		}
		if ("1".equals(transferAcceptedInfo.getSecurity())) {// 安全出口、安全锤
			security = "√";
		}
		if (transferAcceptedInfo.getSecurity() == null
				|| "".equals(transferAcceptedInfo.getSecurity())) {
			security = "";
		}
		if ("1".equals(transferAcceptedInfo.getExternalMarking())) {// 外部标示、文字
			externalMarking = "√";
		}
		if (transferAcceptedInfo.getExternalMarking() == null
				|| "".equals(transferAcceptedInfo.getExternalMarking())) {
			externalMarking = "";
		}
		if ("1".equals(transferAcceptedInfo.getSiren())) {// 标志灯具、警报器
			siren = "√";
		}
		if (transferAcceptedInfo.getSiren() == null
				|| "".equals(transferAcceptedInfo.getSiren())) {
			siren = "";
		}
		if ("1".equals(transferAcceptedInfo.getSecurityTechnology())) {// 安全技术检验合格证明
			securityTechnology = "√";
		}
		if (transferAcceptedInfo.getSecurityTechnology() == null
				|| "".equals(transferAcceptedInfo.getSecurityTechnology())) {
			securityTechnology = "";
		}
		String strVin = "";
		if (StringUtil.isNullOrBlank(transferAcceptedInfo.getLicensePlate())) {
			lvin = transferAcceptedInfo.getVin();
			strVin = "<div class='jp-label jp-comp-13'>";
		} else {
			lvin = transferAcceptedInfo.getLicensePlate();
			strVin = "<div class='jp-label jp-comp-28'>";
		}
		StringBuffer str = new StringBuffer();

		String color = transferAcceptedInfo.getCy_color();
		if (color == null || "".equals(color)) {
			color = "";
		}
		String cy_passenger = transferAcceptedInfo.getCy_passenger();
		if (cy_passenger == null || "".equals(cy_passenger)) {
			cy_passenger = "";
		}
		String cy_carType = transferAcceptedInfo.getCy_carType();
		if (cy_carType == null || "".equals(cy_carType)) {
			cy_carType = "";
		}
		String checkConclusion = transferAcceptedInfo.getCheckConclusion();
		if (checkConclusion == null || "".equals(checkConclusion)) {
			checkConclusion = "";
		}
		String pp = "";
		if(transferAcceptedInfo.getCy_cardType()!=null && !"".equals(transferAcceptedInfo.getCy_cardType()))
		{
			pp = code.getItemValueByItemIdAndItemCode(Codes.PLATE_TYPE,Integer.parseInt(transferAcceptedInfo.getCy_cardType()));
		}
		str.append(""
						+ "<img class='jp-paper-background' src='style/images/memuC.jpg' style='WIDTH: 766px; HEIGHT: 1083px'/>"
						+ "<div class='jp-label jp-comp-1'>"
						+ registration
						+ "</div>"
						+ "<div class='jp-label jp-comp-2'>"
						+ transferRegister
						+ "</div>"
						+ "<div class='jp-label jp-comp-3'>"
						+ changesVacate
						+ "</div>"
						+ "<div class='jp-label jp-comp-4'>"
						+ vinNum
						+ "</div>"
						+ "<div class='jp-label jp-comp-5'>"
						+ engineNum
						+ "</div>"
						+ "<div class='jp-label jp-comp-6'>"
						+ brandModel
						+ "</div>"
						+ "<div class='jp-label jp-comp-7'>"
						+ drivingRecord
						+ "</div>"
						+ "<div class='jp-label jp-comp-8'>"
						+ color
						+ "</div>"
						+ "<div class='jp-label jp-comp-9'>"
						+ cy_passenger
						+ "</div>"
						+ "<div class='jp-label jp-comp-10'>"
						+ cy_carType
						+ "</div>"
						+ "<div class='jp-label jp-comp-11'>"
						+ plateOrTireExterior
						+ "</div>"
						+ "<div class='jp-label jp-comp-12'>"
						+ checkConclusion
						+ "</div>"
						+ strVin
						+ lvin
						+ "</div>"
						+ "<div class='jp-label jp-comp-14'>"
						+ serial
						+ "</div>"
						+ "<div class='jp-label jp-comp-15'>"
						+ pp
						+ "</div>"
						+ "<div class='jp-image jp-comp-16'>"
						+ "<img class=jp-image-view src='"
						+ transferAcceptedInfo.getPhoto_1()
						+ "' style='WIDTH: 99mm; HEIGHT: 65mm'>"
						+ "</div>"
						+ "<div class='jp-label jp-comp-17'>"
						+ tireIntact
						+ "</div>"
						+ "<div class='jp-label jp-comp-18'>"
						+ seatBelt
						+ "</div>"
						+ "<div class='jp-label jp-comp-19'>"
						+ numberAxes
						+ "</div>"
						+ "<div class='jp-label jp-comp-20'>"
						+ tireSize
						+ "</div>"
						+ "<div class='jp-label jp-comp-21'>"
						+ lateralPortionOf
						+ "</div>"
						+ "<div class='jp-label jp-comp-22'>"
						+ reflectiveMark
						+ "</div>"
						+ "<div class='jp-label jp-comp-23'>"
						+ fireExtinguisher
						+ "</div>"
						+ "<div class='jp-label jp-comp-24'>"
						+ security
						+ "</div>"
						+ "<div class='jp-label jp-comp-25'>"
						+ externalMarking
						+ "</div>"
						+ "<div class='jp-label jp-comp-26'>"
						+ siren
						+ "</div>"
						+ "<div class='jp-label jp-comp-27'>"
						+ securityTechnology + "</div>" +
						"<div class='jp-label jp-comp-29'><img src='style/images/guohui.jpg' width='30mm' height='30mm'>" +
						"</div>" +
						"<div class='jp-label jp-comp-30'>大连市公安局交警支队车管所旧车交易市场机动车登记服务站" +
						"</div>" +
						"<div class='jp-label jp-comp-31'><img src='style/images/vin_before.png' width='95mm' height='19mm'>" +
						"</div>" +
						"<div class='jp-label jp-comp-32'><img src='style/images/vin_after.png' width='170mm' height='20mm'></div>");

		String responseText = str.toString();

		uc.setAttribute("lcText", responseText);
		uc.setAttribute("lcPrintFlag", "1");

		responseValues(response, responseText, TEXT);
		logger.debug(this.getClass().getName() + "#execute was completed.");
	}

}
